import * as echarts from 'echarts'

/**
 * 
 * @param {HTMLDivElement} el
 * @param {Array} data
 */
export const chart1 = (el, data) => {
  const chart = echarts.init(el)
  const option = {
    title: {
      text: '折线图一'
    },
    tooltip: {},
    xAxis: {
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      min: 0.0000000001,
      max: 0.1
    },
    series: [
      {
        type: 'line',
        data
      }
    ]
  }
  chart.setOption(option)
  return chart
}

/**
 *  欠缺实现
 *  @param {HTMLDivElement} el
 * @param {Array} originData
 */
export const chart2 = (el, originData) => {
  let data = []
  originData.forEach(item => {
    let count = 0
    let num = Number(item)
    for (let i = 0; num < 1; i++) {
      num = num * 10
      count = i
    }
    data.push(9 - count - 1)
  })
  const chart = echarts.init(el)
  const option = {
    title: {
      text: '阶梯图二'
    },
    tooltip: {},
    xAxis: {
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      min: 0,
      max: 8,
      splitNumber: 4,
      axisLabel: {
        formatter (val, index) {
          return `10-${9-val}`
        }
      }
    },
    series: [
      {
        type: 'line',
        step: true,
        data,
        tooltip: {
          formatter (params) {
            console.log(params)
            return `10-${9 - (params.data)}`
          }
        }
      }
    ]
  }
  chart.setOption(option)
  return chart
}